<template>
  <view>
    <view class="w100 rowscl rowsm pl-36 pr-36 pt-40">
      <view class="w-176 h-176 relative mb-90" @click="uploadImg()">
        <image :src="img ? img : '/static/wd_gr.png'" class="w100 h100 br-88" mode="" style="border: 2rpx solid #487EFF;" ></image>
        <image src="/static/icon_grxxsc-1.png" class="w-52 h-52 absolute" style="bottom: 0;right: 0;" mode=""></image>
      </view>
      
      <view class="w100 rowsb rowsm trt fs-30 mb-60">
        <view class="col888">姓名</view>
        <input type="text" placeholder="请输入姓名" disabled placeholder-class="fs-30 col333" v-model="userInfo.name">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 mb-60">
        <view class="col888">手机号</view>
        <input type="number" placeholder="请输入手机号" disabled maxlength="11" placeholder-class="fs-30 col333" v-model="userInfo.phone">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 mb-60">
        <view class="col888">学校</view>
        <input type="text" placeholder="请输入学校" disabled placeholder-class="fs-30 col333" v-model="userInfo.xxName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 mb-60">
        <view class="col888">学院</view>
        <input type="text" placeholder="请输入学院" disabled placeholder-class="fs-30 col333" v-model="userInfo.xyName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 mb-60">
        <view class="col888">专业</view>
        <input type="text" placeholder="请输入专业" disabled placeholder-class="fs-30 col333" v-model="userInfo.zyName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 mb-60">
        <view class="col888">年级</view>
        <input type="text" placeholder="请输入年级" disabled placeholder-class="fs-30 col333" v-model="userInfo.njName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30">
        <view class="col888">班级</view>
        <input type="text" placeholder="请输入班级" disabled placeholder-class="fs-30 col333" v-model="userInfo.bjName">
      </view>
    </view>
    
    <view class="w100 rowsc rowsm fixed" style="bottom: 80rpx;">
      <view class="w-702 h-84 br-36 rowsc rowsm colfff fs-30 fw-b" style="background: linear-gradient(to bottom,#4897FF,#4878FF);" @click="updateUserInfo()">确定</view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        img:'',
        uploadUrl:'',
        userInfo:{}
      };
    },
    onLoad() {
      this.getUserInfo()
    },
    methods:{
      updateUserInfo(){
        if(!this.uploadUrl) return this.$tools.showtt('请上传头像')
        this.$tools.axiosFromToken('POST','prouser/update',{userImage:this.uploadUrl},'加载中').then(res => {
          this.$tools.showtt(res.msg)
          if(res.code != 200) return
          setTimeout(() => {
            this.$tools.goBack(1)
          },1000)
        })
      },
      uploadImg(){
        uni.chooseImage({
          count:1,
          success:(res) => {
            uni.uploadFile({
              url:this.$tools.avatarUrl + '/api/utils/ossUpload',
              filePath:res.tempFilePaths[0],
              name:'file',
              success:(res1) => {
                console.log(JSON.parse(res1.data).url)
                this.uploadUrl = JSON.parse(res1.data).url
                this.img = this.$tools.avatarUrl+ JSON.parse(res1.data).url
              }
            })
          }
        })
      },
      getUserInfo(){
        this.$tools.axiosFromToken('POST','prouser/getById',{},'加载中').then(res => {
          if(res.code != 200) return this.$tools.showtt(res.msg)
          let {data} = res
          data.userImage = this.$tools.avatarUrl + data.userImage
          this.userInfo = data
          this.img = data.userImage
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
